package com.dupt.common.dingtalk;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiMediaUploadRequest;
import com.dingtalk.api.response.OapiMediaUploadResponse;
import com.taobao.api.FileItem;

/**
 * 钉钉媒体文件上传
 *
 * @author zhuanyu.sun
 * @date 2025-06-11
 */
public class MediaUpload {
    public static String getMedia(String accessToken) throws Exception{
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/media/upload");
        OapiMediaUploadRequest req = new OapiMediaUploadRequest();
        req.setType("image");
        // 要上传的媒体文件
        FileItem item = new FileItem("D:/111.png");
        req.setMedia(item);
        OapiMediaUploadResponse rsp = client.execute(req, accessToken);
        //System.out.println(rsp.getBody());
        return rsp.getMediaId();
    }
}
